<!--#include file="rstojson.inc"-->
<%
Session.codepage = 65001
Dim conn,Rs,gconnstr
'MySQL 5.1 Connection
gconnstr = "DRIVER={MySQL ODBC 5.1 Driver}; UID=root;PWD=01012000;SERVER=localhost;DATABASE=riverrush;"
on error resume next
Set conn=Server.CreateObject("Adodb.Connection")
Conn.Open gconnstr
Set Rs = Server.CreateObject("Adodb.Recordset")
if err<>0 then
response.write err.description
end if
%>

<%
	if request("submit")<>"" then
		name = replace(request("name"),"'","")
		location = replace(request("location"),"'","")
		score = replace(request("score"),"'","")
		
		if name<>"" and location<>"" and score<>"" then
			if len(name)<20 and len(location)<5 and len(score)<5 then
				conn.execute "INSERT INTO highscores (USERNAME,HIGHSCORE,LOCATION,SUBMITDATE) VALUES ('"&name&"','"&score&"','"&location&"',NOW())"
			end if
		end if
	end if
	
	if request("list")<>"" and IsNumeric(request("page")) then

		rs.open "SELECT USERNAME as name,LOCATION as location,HIGHSCORE as score,SUBMITDATE as sdate from highscores order by score desc limit "&request("page")*5&",5",conn
		if rs.eof then
			response.write "null"
		else
			response.write RStoJSON(rs)
		end if
	end if

%>